var notNULL = "不能为空";
var notInSpace = "大小不在指定区间";

function Check() {
    var check = 50;
    $(".input-group").each(function () {
        var obj = $(this);
        var value = obj.val();
        var desc = $(this).parent().prev().text();
        desc = desc.substring(0, desc.length - 1);
        if (check != 50) {
            return false;
        }
        //检测非空        
        if ($(this).val() == null || $(this).val() == "" || $(this).val() == "0") {
            if ($(this).attr("notNULL") == "true") {
                alert(desc + notNULL);
                check = 99;
                return 99;
            }
        }
//检测合法性*****************************************************************************************************************************************************************************/
        var dataType = obj.attr("data_type");
        if (dataType != undefined && dataType != null && dataType != "") {
            var dataArray = dataType.split(",");
            debugger
            if (dataArray[0] == "NUM") {
                value = parseInt(value);                            //检测数字大小  格式  data_type="NUM,0,120"     大于0小于120
                alert(value < dataArray[1] || value > dataArray[2])
                if (value < dataArray[1] || value > dataArray[2]) {
                    alert(desc + notInSpace);
                    check = 99;
                    return 99;
                }
            } else if (dataArray[0] == "LENGTH") {
                if (value.length < dataArray[1] || value.length > dataArray[2]) {       //检测字符串长度    格式  data_type="LENGTH,0,12"   
                    alert(desc + "长度不在指定区间");
                    check = 99;
                    return 99;
                }
            }
            // else if(){
            // }
        }
    });
    return check;
}

//**********************************************************************************************************************************************************************************/
var responseData = window.localStorage;//   页面数据存储对象
function cutPicture(dataJson) {
    var url = dataJson.url;
    var str = JSON.stringify(dataJson);
    responseData.setItem("data", str);
    console.log(responseData);
    var log = "<iframe width='100%' height='100%' scrolling='no' id='picture_update' src='" + url + "'></iframe>"
    var cont = "<div id = 'cont' style='width:1903px;height:969px;position: fixed;z-index: 956;top:0px;'>" + log + "</div>"
    $("html", parent.document).append(cont);
}

//获取传输到下个页面的数据
function getTransferValue() {
    var url = window.location.href;
    var index = url.lastIndexOf("/") + 1;
    url = url.substring(index);
    alert(url);
    var returnData = JSON.parse(responseData.data)
    index = returnData.url.lastIndexOf("/") + 1;
    url1 = returnData.url.substring(index);
    if (url != url1) {
        alert("信息验证不通过")
        return false;
    }
    return returnData;
}

function transferToNextWindow(dataJson) {
    var url = window.location.href;
    var index = url.lastIndexOf("/") + 1;
    url = url.substring(index);
    console.log("当前页面是" + url)
    url = "../html/" + url;
    var id = $("iframe[src='" + url + "']", parent.document).attr("id")
    var num = parseInt(id.substring(id.length - 1)) + 1;//通过id后缀判断当前页面
    var nextIframe = $("#iframe" + num, parent.document);
    nextIframe.length > 0 ? console.log("存在") : console.log("不存在");//判断下一个页面是否存在    存在则刷新    不存在则生成并插入div
    var exist = nextIframe.length > 0;
    if (!exist) {
        var nextWindow = "<div id='transfer" + num + "' class = 'room'><iframe width='100%' height='100%' scrolling='no' id='iframe" + num + "' src='" + url + "'></iframe></div>"
        $("#showArea", parent.document).append(nextWindow);
    } else {
        nextIframe.attr("src", url);   //刷新页面
    }
    var url = dataJson.url;    //获取数据需要传输过去的页面地址
    var str = JSON.stringify(dataJson);  //转化json为字符串
    responseData.setItem("data", str);
    console.log(responseData);
    $(".room", parent.document).each(function () {
        var state = $(this).attr("state");
        if (state == "on") {
            $(this).attr("state", "");
        } else {
            $(this).attr("state", "on");
            $(this).children("iframe").attr("src", url)   //给入场窗口赋值
        }
    })
    //根据入场方式  开始入场动画
    var moveType = dataJson.moveType;    //入场方式    跟这参数传过来
    moveAction(moveType);       //执行页面变换
}

function backToLastWindow(moveType) {

    var url = window.location.href;
    var index = url.lastIndexOf("/") + 1;
    url = url.substring(index);
    console.log("当前页面是" + url)
    url = "../html/" + url;
    var id = $("iframe[src='" + url + "']", parent.document).attr("id")
    var num = id.substring(id.length - 1);//通过id后缀判断当前页面
    if (num == "1") {
        alert("当前是第一级窗口，无法后退")
        return false;
    }
    num = num - 1; //上一级窗口的id
    $(".room", parent.document).each(function () {
        var id = $(this).attr("id");
        var IsSame = id == "transfer" + num;

        if (IsSame) {
            $(this).attr("state", "on");
        } else {
            $(this).attr("state", "");
        }
    })
    moveAction(moveType);       //执行页面变换

}

function moveAction(moveType) {                                          ///TODO   还有其他变换样式 待开发！！
    if (moveType == null || moveType == "") {   //如果没有选择入场动画 则默认秒显示
        $(".room[state='on']", parent.document).show();
        $(".room[state='']", parent.document).hide();
    }
}





